<?php
namespace app\blog\controller;
use cmf\controller\AdminBaseController;
use think\Db;

class SwitchController extends AdminBaseController
{
   /*
    * 首页
    * */
   public function index()
   {
      $state=DB::name('switch')->find();
      $this->assign('state',$state);
      return $this->fetch();
   }
   /*
    * 更新状态
    * */
   public function updata()
   {
     $switch=DB::name('switch')->find();
     $res=$this->request->param();
     if($switch)
     {
         $where['id']=$switch['id'];
         $array['vipprice_status']=$res['state'];
         $array['time']=time();
         $status=DB::name('switch')->where($where)->update($array);
     }else{
         $array['vipprice_status']=$res['state'];
         $array['time']=time();
         $status=DB::name('switch')->insert($array);
     }
     if($status)
     {
         $this->success('操作成功');
     }else{
         $this->error('操作失败');
     }
   }
}
